package com.wchen.gdoc.generate.config;

import org.springframework.util.StringUtils;

import java.util.Properties;

/**
 * sql相关配置
 *
 * @author  wchen
 * @date    2019/11/11
 */
public class SqlConfig {

    /**
     * 查询项目id sql
     */
    private String queryProjectIdSql;

    /**
     * 查询模块id sql
     */
    private String queryModuleIdSql;

    /**
     * 查询类信息id sql
     */
    private String queryClassIdSql;

    /**
     * 查询方法id sql
     */
    private String queryMethodIdSql;

    /**
     * 新增类信息sql
     */
    private String insertClassSql;

    /**
     * 新增方法信息sql
     */
    private String insertMethodSql;


    protected static SqlConfig initCoreConfig(Properties prop){
        SqlConfig sqlConfig = new SqlConfig();
        String queryProjectIdSql = prop.getProperty(Constant.SQL_PROJECT_SELECT_ID);
        String queryModuleIdSql = prop.getProperty(Constant.SQL_MODULE_SELECT_ID);
        String queryClassIdSql = prop.getProperty(Constant.SQL_CLASS_SELECT_ID);
        String queryMethodIdSql = prop.getProperty(Constant.SQL_METHOD_SELECT_ID);
        String insertClassSql = prop.getProperty(Constant.SQL_CLASS_INSERT);
        String insertMethodSql = prop.getProperty(Constant.SQL_METHOD_INSERT);

        if(!StringUtils.isEmpty(queryProjectIdSql)){
            sqlConfig.setQueryProjectIdSql(queryProjectIdSql);
        }
        if(!StringUtils.isEmpty(queryModuleIdSql)){
            sqlConfig.setQueryModuleIdSql(queryModuleIdSql);
        }
        if(!StringUtils.isEmpty(queryClassIdSql)){
            sqlConfig.setQueryClassIdSql(queryClassIdSql);
        }
        if(!StringUtils.isEmpty(queryMethodIdSql)){
            sqlConfig.setQueryMethodIdSql(queryMethodIdSql);
        }
        if(!StringUtils.isEmpty(insertClassSql)){
            sqlConfig.setInsertClassSql(insertClassSql);
        }
        if(!StringUtils.isEmpty(insertMethodSql)){
            sqlConfig.setInsertMethodSql(insertMethodSql);
        }

        return sqlConfig;
    }

    protected void validityCheck(){

    }


    public String getQueryProjectIdSql() {
        return queryProjectIdSql;
    }

    public void setQueryProjectIdSql(String queryProjectIdSql) {
        this.queryProjectIdSql = queryProjectIdSql;
    }

    public String getQueryModuleIdSql() {
        return queryModuleIdSql;
    }

    public void setQueryModuleIdSql(String queryModuleIdSql) {
        this.queryModuleIdSql = queryModuleIdSql;
    }

    public String getQueryClassIdSql() {
        return queryClassIdSql;
    }

    public void setQueryClassIdSql(String queryClassIdSql) {
        this.queryClassIdSql = queryClassIdSql;
    }

    public String getQueryMethodIdSql() {
        return queryMethodIdSql;
    }

    public void setQueryMethodIdSql(String queryMethodIdSql) {
        this.queryMethodIdSql = queryMethodIdSql;
    }

    public String getInsertClassSql() {
        return insertClassSql;
    }

    public void setInsertClassSql(String insertClassSql) {
        this.insertClassSql = insertClassSql;
    }

    public String getInsertMethodSql() {
        return insertMethodSql;
    }

    public void setInsertMethodSql(String insertMethodSql) {
        this.insertMethodSql = insertMethodSql;
    }
}
